# 数组
puts [1,3,5,4,2].max
lans = %w{ Ruby C APL Perl Smalltalk }
puts lans.min
# 太空船
puts lans.min {|a,b| a.size <=> b.size}
puts lans.min_by {|lang| lang.size}
puts lans.minmax
puts lans.minmax_by {|lang| lang.size}
# 散列
state_hash = {"New York" => "NY", "Maine" => "ME", "Alaska" => "AK","Albama" => "AL"}
# 通过键值判断
p state_hash.min
p state_hash.min_by {|name, abbr| name}
p state_hash.min_by {|name, abbr| abbr}
# 与each相关
[1,2,3].reverse_each {|e| puts e*10}
names = ["George Washington", "John Adams","Thomas Jefferson","James Madison"]
names.each_with_index do |pres, i|
	puts "#{i+1}. #{pres}"
end

#新写法
names.each.with_index(1) do |pres, i|
	puts "#{i} #{pres}"
end

%w{a b c}.each_index {|i| puts i}
letters = {"a" => "ay", "b" => "bee", "c" => "see"}
letters.each_with_index{|(key,value),i| puts i}
#新写法
letters.each.with_index{|(key,value),i| puts i}
#散列each_index会报错
#letters.each_index{|(key,value),i| puts i}
array = [1,2,3,4,5,6,7,8,9,10]
array.each_slice(3) {|slice| p slice}
array.each_cons(3) {|cons| p cons}
